<?php
/*
 * 手机客户端 测试文件上传
 * 2013-12-14
 */
include "inc/public_header.php";
include "func/user.php";				//用户信息处理函数


//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array(
		 "success"=>"0"
		,"errCode"=>"0"
		,"msg"=>"没有获取到用户信息"
		,"uuid"=>$_REQUEST["uuid"]));
	die;
}
$uid = $uInfoArr["uid"]; //用户信息主键


$nickName 		= $_REQUEST["nickName"];		//昵称
$realName 		= $_REQUEST["realName"];		//真实姓名
$sex 			= $_REQUEST["sex"];				//性别
$birthday 		= $_REQUEST["birthday"];		//生日
//$cardType		= $_REQUEST["cardType"];		//证件类型
//$cardNumber 	= $_REQUEST["cardNumber"];		//号码
$email 			= $_REQUEST["email"];			//邮箱
$college 		= $_REQUEST["college"];			//学校
$major  		= $_REQUEST["major"];			//专业
//$studentId  	= $_REQUEST["studentId"];		//学号
$entrance  		= $_REQUEST["entrance"];		//入学年份
$isStudent		= $_REQUEST["isStudent"];		//学生

if(!isset($sex)){
	echo json_encode(array("success"=>"0","errCode"=>"2","msg"=>"请输入您的性别"));
	die;
}

if(!isset($birthday)){
	echo json_encode(array("success"=>"0","errCode"=>"3","msg"=>"请输入您的生日"));
	die;
}
/*
if(!isset($cardType)){
	echo json_encode(array("success"=>"0","errCode"=>"4","msg"=>"请选择您的证件类型"));
	die;
}
if(!isset($cardNumber)){
	echo json_encode(array("success"=>"0","errCode"=>"5","msg"=>"请输入您的证件号码"));
	die;
}*/
if(!isset($email)){
	echo json_encode(array("success"=>"0","errCode"=>"6","msg"=>"请输入您的邮箱"));
	die;
}

//上传基础信息
$sql = "update user_base set sex='".$sex."',birthday='".$birthday."',email='".$email."' ";
if($realName){
	$sql = $sql.",realname='".$realName."'";
}
$sql = $sql."where uid='".$uid."'";
$db->query($sql);


//判断是否存在大赛信息，如果没有则新建
$xx_sql="select * from new_weituo_person  where uid='".$uid."'";
$db->query($xx_sql);
if($db->next_record()){
	$ifExist = "1";
}else{
	$x_sql="insert into new_weituo_person set uid='".$uid."',createtime=now()";
	$db->query($x_sql);
}
/*
//大赛信息上传
$ds_sql="update new_weituo_person set update_datetime=now()";
if($college){
	$ds_sql = $ds_sql.",xuexiao='".$college."'";
}
if($major){
	$ds_sql = $ds_sql.",zhuanye='".$major."'";
}
if($entrance){
	$ds_sql = $ds_sql.",year='".$entrance."'";
}
if($nickName){
	$ds_sql = $ds_sql.",nickname='".$nickName."'";
}
if($studentId){
	$ds_sql = $ds_sql.",xuehao='".$studentId."'";
}
$ds_sql = $ds_sql." where uid='".$uid."'";
$db->query($ds_sql);
*/
if(!$college){
$college= "";
$major= "";
$entrance= "";
//$studentId= "";
$isStudent='1';

}


$sql="update new_weituo_person set update_datetime=now(),xuexiao='".$college."',zhuanye='".$major."',year='".$entrance."',nickname='".$nickName."',sex='".$sex."',email='".$email."' ";
if($realName){
	$sql = $sql.",realname='".$realName."'";
}
$sql = $sql."where uid='".$uid."'";
$db->query($sql);

//图片根路径
$BASE_UPLOAD_PATH = "/img1/uploads/zjl_ilogo/"; 
//图片显示根路径
$SHOW_IMG_BASE_URL = "http://www.chinalaohu.com/img1/uploads/zjl_ilogo/";

$uploadOK 		= false; 	//是否上传成功
$zuopinId 		= "";		//作品主键
$fImgPath 		= ""; 		//第一张图片文件名
$fImgId 		= ""; 		//第一张图片信息主键
$reUrl 			= array(); 	//返回图片url
$oldNames 		= "";		//上传的文件原名序列
$newNames		= "";		//上传后的文件名序列
$upFileCount	= 0;
foreach((array)$_FILES['img_file']['tmp_name'] as $k=>$v){
	if($_FILES['img_file']['name'][$k]!=""){
		$tmpPath = $_FILES['img_file']['tmp_name'][$k];
		$oldFileName = basename($_FILES['img_file']['name'][$k]);
		$extName = explode(".",$oldFileName);
		$extName = $extName[count($extName)-1];
		$newFileName = $uid."_".date("YmdHms")."_".$k."_".".".$extName;
		if($oldNames==""){
			$oldNames = $oldFileName;
		}else{
			$oldNames = $oldNames.",".$oldFileName;
		}
		$upFileCount++;
		if(!$oldFileName){
			continue;
		}

		if(strtolower($extName)!="jpg" && strtolower($extName)!="jpeg"){

			echo json_encode(array("success"=>"0","errCode"=>"6","msg"=>"上传的图片只能是jpg/jpeg格式(".$oldFileName.")"));
			die;
		}
		if($newNames==""){
			$newNames = $newFileName;
		}else{
			$newNames = $newNames.",".$newFileName;
		}
		$uploaddir = $_SERVER["DOCUMENT_ROOT"].$BASE_UPLOAD_PATH;

		if(move_uploaded_file($tmpPath,$uploaddir.$newFileName)){

			// 上传成功，处理语句信息

			$sql="update new_weituo_person set ilogo_path='".$newNames."' where uid='".$uid."'";
			$db->query($sql);

			 $reUrl[] = $SHOW_IMG_BASE_URL.$newFileName;
			
		}
	}
}
$uploadOK = ture;


if($uploadOK){
echo json_encode(array(
		"success"=>"1"
		//,"old_file_names"=>$oldNames
		//,"new_file_names"=>$newNames
		//,"upload_files_count"=>(string)$upFileCount
		,"msg"=>"上传成功"
		,"imgUrls"=>$reUrl[0]));
}else{
	echo json_encode(array("success"=>"0","errCode"=>"7"));
}
die;

?>